/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2024-08-20 09:29:11
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2024-08-20 09:32:50
 * @FilePath: /vue3-uniapp/src/service/utils/useThrottleFn.ts
 */
import { throttleFn } from '@/utils/index';

export const useThrottleFn = <T extends (...args: any[]) => any>(
    fn: T,
    limit: number
): [(...args: Parameters<T>) => void, () => void] => {
    const [excute, clear] = throttleFn(fn, limit);

    // 组件卸载时清除定时器
    onBeforeUnmount(clear);

    return [excute, clear];
};
